package GUI_Data.User;

import Data_Flow.DataOperator;
import Data_Flow.GetData;
import Data_Structure.DataType.MyFlight;
import GUI_Data.FlightSeatPanel.SeatButton;
import lombok.Data;

import javax.swing.*;
import java.awt.*;
import java.awt.event.FocusEvent;
import java.awt.event.FocusListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.HashMap;

/**
 * This class contains all the Buttons and the variables needed in GUI logic.
 * @author Xiaorun Wang
 * @author Chunxi Lin
 * @author Yibai Jiang
 * @author Shunhao Yan
 */
@Data
public class AllButton {
    private int extraMeal = 0;


    private AllButton thisObject;
    private GetData getData;
    private DataOperator dataOperator;
    //1 for booking number, 2 for surname, 3 for scan
    private int loginMethod = 1;

    //1 for surname, 2 for id
    private int inputMethod = 0;

    private boolean ifCapsLock = false;

    private boolean ifPayed = false;

    private SeatButton targetSeat;

    private NewButton exitButton = new NewButton("Exit  ","red",2);

    private NewButton backToOrigin = new NewButton("     Origin","green",3);
    private NewButton backToDisplay = new NewButton("    Display","white",3);
    private NewButton backToSeatChoose = new NewButton("Seat choose","white",3);
    private NewButton backToMealChoose = new NewButton("Meal choose","white",3);
    private NewButton backToPay = new NewButton("      Pay","white",3);
    private NewButton backToPrinting = new NewButton("    Printing","white",3);
    private NewButton lastButton = new NewButton(" Last page","grey",1);
    private NewButton nextButton = new NewButton(" Next page","grey",1);

    private JButton[] keyboard1;
    private JButton[] keyboard2;
    private JButton capsLock = new JButton("CapsClock");
    private JButton capsLock2 = new JButton("CapsClock");

    private NewButton originBooking = new NewButton("Booking number","grey",1);
    private NewButton originID = new NewButton("Surname and ID","grey",1);
    private NewButton originScan = new NewButton("   Scan ID card","grey",1);
    private JButton originDelete = new JButton("delete");
    private JButton originDelete2 = new JButton("delete");
    private NewButton originConfirm = new NewButton("       confirm","grey",1);

    /* JButton */
    private JButton scanConfirm;

    private NewButton displaySeatChoose = new NewButton("   upgrade seat","grey",1);
    private NewButton displayMealChoose = new NewButton("   upgrade meal","grey",1);
    private NewButton checkIn = new NewButton("      check-in","grey",1);

    private NewButton payPay = new NewButton("          pay","grey",1);
    private NewButton payCancel = new NewButton("       cancel","grey",1);

    private NewButton printAll = new NewButton("       print all","grey",1);

    private NewButton printingBack = new NewButton("         back","grey",1);

    private NewButton printFinish = new NewButton("        Finish","grey",1);

    private NewButton payFinish = new NewButton("      Finish","grey",1);

    private NewButton buttonInSeatChooseConfirm = new NewButton("      Confirm","grey",1);
    private NewButton buttonInSeatChooseCancelSelect = new NewButton("Cancel selecting","grey",1);

    private NewButton buttonInMealChooseConfirm = new NewButton("      Confirm","grey",1);
    private NewButton buttonInMealChooseCancelSelect = new NewButton("Cancel selecting","grey",1);
    private NewButton buttonInMealChooseReturn = new NewButton("       Return","grey",1);

    private NewButton buttonInExtraSeatChooseConfirm = new NewButton("      Confirm","grey",1);
    private NewButton buttonInExtraSeatChooseCancelSelect = new NewButton("Cancel selecting","grey",1);
    private NewButton buttonInExtraSeatChooseReturn = new NewButton("       Return","grey",1);

    private NewButton buttonInExtraMealChooseConfirm = new NewButton("      Confirm","grey",1);
    private NewButton buttonInExtraMealChooseCancelSelect = new NewButton("Cancel selecting","grey",1);
    private NewButton buttonInExtraMealChooseReturn = new NewButton("       Return","grey",1);

    /**
     * The generator of AllButton
     * Initialize all buttons on the login page.
     * @param userFrame The userFrame which contains this AllButton class.
     * @param dimension The dimension information.
     */
    public AllButton(UserFrame userFrame, SetDimension dimension) {

        //Yan Shunhao
        setButtonSize(dimension);

        thisObject = this;

        backToDisplay.setEnabled(false);

        backToSeatChoose.setEnabled(false);

        backToMealChoose.setEnabled(false);

        backToPay.setEnabled(false);

        backToPrinting.addActionListener(userFrame);
        backToPrinting.setEnabled(false);

        int index = 0;
        keyboard1 = new JButton[AllData.keyboardChar.length];
        keyboard2 = new JButton[AllData.keyboardChar.length];
        for (char i : AllData.keyboardChar) {
            getKeyboard2()[index] = new JButton(String.valueOf(i));
            getKeyboard2()[index].setPreferredSize(dimension.getKeyboardDimension());
            getKeyboard1()[index] = new JButton(String.valueOf(i));
            getKeyboard1()[index].setPreferredSize(dimension.getKeyboardDimension());
            index++;
        }
        capsLock.setBackground(Color.WHITE);
        capsLock2.setBackground(Color.WHITE);

        ImageIcon imgScan = new ImageIcon("src/GUI_Data/Sources/Background/scanButton.png");
        scanConfirm = new JButton(imgScan);
        Image temp = imgScan.getImage().getScaledInstance((int) dimension.getScanConfirmDimension().getWidth(), (int) dimension.getScanConfirmDimension().getHeight(), Image.SCALE_DEFAULT);
        imgScan = new ImageIcon(temp);
        scanConfirm = new JButton(imgScan);
        scanConfirm.setOpaque(false);
        scanConfirm.setContentAreaFilled(false);
        scanConfirm.setHorizontalTextPosition(SwingConstants.CENTER);
    }

    /**
     * This method is used to add listening actions to all buttons.
     * This method is called when the window is initialized and reset.
     * @param userFrame The userFrame which contains this AllButton class.
     * @param dimension All the dimension information.
     * @param allPanel All the JPanel objects.
     * @param allLabelAndTextField All the JLabel and JTextField objects.
     * @param card The CardLayout object of the center panel.
     * @param login The CardLayout object of the input panel in login page.
     */
    public void addActionPerform(UserFrame userFrame, SetDimension dimension,AllPanel allPanel, AllLabelAndTextField allLabelAndTextField, CardLayout card, CardLayout login){
        exitButton.addActionListener(e -> System.exit(0));

        backToOrigin.addActionListener(e -> card.show(allPanel.getCenterPanel(),"Origin page"));
        backToSeatChoose.addActionListener(e -> card.show(allPanel.getCenterPanel(),"Seat choose page"));
        backToDisplay.addActionListener(e -> toDisplayPage(allLabelAndTextField, allPanel, card));
        backToMealChoose.addActionListener(e -> card.show(allPanel.getCenterPanel(),"Meal choose page"));
        backToPay.addActionListener(e -> toPayPage(dimension,allLabelAndTextField,allPanel,card,getData));

        scanConfirm.addActionListener(e -> {
            allLabelAndTextField.getSur().setText("san");
            allLabelAndTextField.getId().setText("11010520010201");
            ifCapsLock = false;
            capsLock2.setBackground(Color.WHITE);
            capsLock2.setForeground(Color.BLACK);
            loginMethod = 2;
            login.show(allPanel.getInputPanel(),"sur and ID");
        });
        originBooking.addActionListener(e -> {
            login.show(allPanel.getInputPanel(),"booking number");
            ifCapsLock = false;
            capsLock.setBackground(Color.WHITE);
            capsLock.setForeground(Color.BLACK);
            inputMethod = 0;
            loginMethod = 1;
        });
        originID.addActionListener(e -> {
            login.show(allPanel.getInputPanel(),"sur and ID");
            ifCapsLock = false;
            capsLock2.setBackground(Color.WHITE);
            capsLock2.setForeground(Color.BLACK);
            loginMethod = 2;
        });
        originScan.addActionListener(e -> {
            login.show(allPanel.getInputPanel(),"scan");
            inputMethod = 0;
            loginMethod = 3;
        });

        allLabelAndTextField.getSur().addFocusListener(new FocusListener() {
            @Override
            public void focusGained(FocusEvent e) {
                inputMethod = 1;
            }

            @Override
            public void focusLost(FocusEvent e) {

            }
        });

        allLabelAndTextField.getId().addFocusListener(new FocusListener() {
            @Override
            public void focusGained(FocusEvent e) {
                inputMethod = 2;
            }

            @Override
            public void focusLost(FocusEvent e) {

            }
        });
        originConfirm.addActionListener(e -> {
            if(loginMethod == 1){
                getData = new GetData(allLabelAndTextField.getNum().getText());
                dataOperator = new DataOperator(allLabelAndTextField.getNum().getText());
                if (getData.isIfSuccess() && dataOperator.isIfSuccess()){
                    if (getData.getMySeatPosition().equals("")){
                        allLabelAndTextField.init(getData);
                        allPanel.init(userFrame,dimension,this,getData);
                        backToOrigin.setEnabled(false);
                        backToOrigin.changeColor("grey");
                        backToSeatChoose.setEnabled(true);
                        backToSeatChoose.changeColor("green");
                        card.show(allPanel.getCenterPanel(),"Seat choose page");
                    }else {
                        JOptionPane.showMessageDialog(userFrame,"Sorry, you have already checked in. If you need to handle other business, please go to the manual counter.","Login failed",JOptionPane.ERROR_MESSAGE);
                        userFrame.init();
                    }

                }
                else{
                    allLabelAndTextField.getInput_bookingNum().setForeground(Color.RED);
                    allLabelAndTextField.getInput_bookingNum().setText("Not match! Please check your input:");
                }
            }else if(loginMethod == 2){
                getData = new GetData(allLabelAndTextField.getId().getText(),allLabelAndTextField.getSur().getText());
                dataOperator = new DataOperator(allLabelAndTextField.getId().getText(),allLabelAndTextField.getSur().getText());
                if(getData.isIfSuccess() && dataOperator.isIfSuccess()){
                    allLabelAndTextField.preInit(getData);
                    allPanel.preInit(allLabelAndTextField);
                    allLabelAndTextField.getFlightTable().addMouseListener(new MouseAdapter() {
                        public void mouseClicked(MouseEvent e) {
                            int index = allLabelAndTextField.getFlightTable().getSelectedRow();
                            getData.ChooseFlightByFlightID(allLabelAndTextField.getFlightList()[index][0].toString());
                            dataOperator.ChooseFlightByFlightID(allLabelAndTextField.getFlightList()[index][0].toString());
                            if (getData.isIfSuccess() && dataOperator.isIfSuccess()){
                                if (getData.getMySeatPosition().equals("")){
                                    allLabelAndTextField.init(getData);
                                    allPanel.init(userFrame,dimension,thisObject,getData);
                                    backToOrigin.setEnabled(false);
                                    backToOrigin.changeColor("grey");
                                    backToSeatChoose.setEnabled(true);
                                    backToSeatChoose.changeColor("green");
                                    card.show(allPanel.getCenterPanel(),"Seat choose page");
                                }else {
                                    JOptionPane.showMessageDialog(userFrame,"Sorry, you have already checked in. If you need to handle other business, please go to the manual counter.","Login failed",JOptionPane.ERROR_MESSAGE);
                                    userFrame.init();
                                }
                            }else {
                                JOptionPane.showMessageDialog(userFrame,"Sorry, system error, please contact staff.","Login failed",JOptionPane.ERROR_MESSAGE);
                                userFrame.init();
                            }
                            allLabelAndTextField.getFlightTable().getSelectionModel().clearSelection();

                        }
                    });
                    card.show(allPanel.getCenterPanel(),"booked page");
                }
                else{
                    allLabelAndTextField.getInput_Sur_ID().setForeground(Color.RED);
                    allLabelAndTextField.getInput_Sur_ID().setText("Not match! Please check your input:");
                }
            }
        });

        originDelete.addActionListener(e -> {
            if (loginMethod == 1){
                if (allLabelAndTextField.getNum().getText() != null)
                    allLabelAndTextField.getNum().setText(allLabelAndTextField.getNum().getText().substring(0, allLabelAndTextField.getNum().getText().length()-1));
            }else if (loginMethod == 2){
                if (inputMethod == 1){
                    if (allLabelAndTextField.getSur().getText() != null)
                        allLabelAndTextField.getSur().setText(allLabelAndTextField.getSur().getText().substring(0, allLabelAndTextField.getSur().getText().length()-1));
                }else if (inputMethod == 2){
                    if (allLabelAndTextField.getId().getText() != null)
                        allLabelAndTextField.getId().setText(allLabelAndTextField.getId().getText().substring(0, allLabelAndTextField.getId().getText().length()-1));
                }
            }
        });

        for (int i = 0; i < keyboard1.length; i++) {
            int finalI = i;
            getKeyboard1()[i].addActionListener(e -> {
                if (ifCapsLock)
                    allLabelAndTextField.getNum().setText(allLabelAndTextField.getNum().getText() + AllData.keyboardChar[finalI]);
                else
                    allLabelAndTextField.getNum().setText(allLabelAndTextField.getNum().getText() + AllData.keyboardChar[finalI].toString().toLowerCase());
            });
            getKeyboard2()[i].addActionListener(e -> {
                if (inputMethod == 1){
                    if (ifCapsLock)
                        allLabelAndTextField.getSur().setText(allLabelAndTextField.getSur().getText() + AllData.keyboardChar[finalI]);
                    else
                        allLabelAndTextField.getSur().setText(allLabelAndTextField.getSur().getText() + AllData.keyboardChar[finalI].toString().toLowerCase());
                }

                else if (inputMethod == 2){
                    if (ifCapsLock)
                        allLabelAndTextField.getId().setText(allLabelAndTextField.getId().getText() + AllData.keyboardChar[finalI]);
                    else
                        allLabelAndTextField.getId().setText(allLabelAndTextField.getId().getText() + AllData.keyboardChar[finalI].toString().toLowerCase());
                }

            });
        }
        capsLock.addActionListener(e -> {
            if (ifCapsLock){
                capsLock.setBackground(Color.WHITE);
                capsLock.setForeground(Color.BLACK);
            }else {
                capsLock.setBackground(Color.BLACK);
                capsLock.setForeground(Color.WHITE);
            }
            ifCapsLock = !ifCapsLock;
        });

        capsLock2.addActionListener(e -> {
            if (ifCapsLock){
                capsLock2.setBackground(Color.WHITE);
                capsLock2.setForeground(Color.BLACK);
            }else {
                capsLock2.setBackground(Color.BLACK);
                capsLock2.setForeground(Color.WHITE);
            }
            ifCapsLock = !ifCapsLock;
        });

        buttonInSeatChooseConfirm.addActionListener(e->{
            targetSeat = allPanel.getFlightSeatPanel().confirmChange();
            if(targetSeat == null){
                JOptionPane.showMessageDialog(userFrame, "You haven't selected a seat!");
            }else {
                allLabelAndTextField.getSeat().setText("Seat:" + targetSeat.getSeatClass() + "  " + targetSeat.getSeatPosition());
                backToMealChoose.setEnabled(true);
                backToMealChoose.changeColor("green");
                card.show(allPanel.getCenterPanel(),"Meal choose page");
                //The content should be modified here
            }
        });
        buttonInSeatChooseCancelSelect.addActionListener(e -> allPanel.getFlightSeatPanel().returnBack());

        buttonInMealChooseConfirm.addActionListener(e -> {
            backToDisplay.setEnabled(true);
            backToDisplay.changeColor("green");
            allLabelAndTextField.getWelcome().setText("Welcome " + allLabelAndTextField.getNum().getText());
            toDisplayPage(allLabelAndTextField,allPanel,card);
        });
        buttonInMealChooseCancelSelect.addActionListener(e -> {
            for (int i = 0; i < allPanel.getMealsChooseNum().length; i++) {
                allPanel.getMealsChooseBoxes()[0].setSelected(true);
            }
        });
        buttonInMealChooseReturn.addActionListener(e -> {
            int n = JOptionPane.showConfirmDialog(userFrame, "Your selection will not be saved, confirm to return？",
                    "",JOptionPane.YES_NO_OPTION);
            if (n==0) {
                for (int i = 0; i < allPanel.getMealsChooseBoxes().length; i++) {
                    allPanel.getMealsChooseBoxes()[i].setSelected(false);
                }
                card.show(allPanel.getCenterPanel(), "Seat choose page");
            }
        });

        checkIn.addActionListener(e -> {
            if ((targetSeat.getSeatClass().equals(getData.getMySeatClass()) && extraMeal == 0) || ifPayed){
                backToPrinting.setEnabled(true);
                backToPrinting.changeColor("green");
                card.show(allPanel.getCenterPanel(), "Printing page");
            } else {
                toPayPage(dimension,allLabelAndTextField,allPanel,card,getData);
            }
        });
        displaySeatChoose.addActionListener(e -> {
            if (getData.getMySeatClass().equals("ClassA"))
                JOptionPane.showMessageDialog(userFrame, "You have been the supreme grade.");
            else
                card.show(allPanel.getCenterPanel(),"Extra Seat choose page");
        });
        displayMealChoose.addActionListener(e -> card.show(allPanel.getCenterPanel(),"Extra Meal choose page"));

        buttonInExtraSeatChooseConfirm.addActionListener(e -> {
            SeatButton targetSeatTemp = allPanel.getExtraFlightSeatPanel().confirmChange();
            if(targetSeatTemp == null){
                JOptionPane.showMessageDialog(userFrame, "You haven't selected a seat!");
            }else {
                targetSeat = targetSeatTemp;
                allLabelAndTextField.getSeat().setText("Seat:" + targetSeat.getSeatClass() + "  " + targetSeat.getSeatPosition());
                toDisplayPage(allLabelAndTextField,allPanel,card);
            }
        });
        buttonInExtraSeatChooseCancelSelect.addActionListener(e -> allPanel.getExtraFlightSeatPanel().returnBack());
        buttonInExtraSeatChooseReturn.addActionListener(e -> {
            int n = JOptionPane.showConfirmDialog(userFrame, "Your selection will not be saved, confirm to return？",
                    "",JOptionPane.YES_NO_OPTION);
            if (n==0) {
                allPanel.getExtraFlightSeatPanel().returnBack();
                toDisplayPage(allLabelAndTextField,allPanel,card);
            }
        });

        buttonInExtraMealChooseConfirm.addActionListener(e -> toDisplayPage(allLabelAndTextField,allPanel,card));
        buttonInExtraMealChooseCancelSelect.addActionListener(e -> {
            for (int i = 0; i < allPanel.getExtraMealsChooseNumBoxes().length; i++) {
                allPanel.getExtraMealsChooseNumBoxes()[i].setSelectedIndex(0);
            }
        });
        buttonInExtraMealChooseReturn.addActionListener(e -> {
            int n = JOptionPane.showConfirmDialog(userFrame, "Your selection will not be saved, confirm to return？",
                    "",JOptionPane.YES_NO_OPTION);
            if (n==0) {
                for (int i = 0; i < allPanel.getExtraMealsChooseNumBoxes().length; i++) {
                    allPanel.getExtraMealsChooseNumBoxes()[i].setSelectedIndex(0);
                }
                toDisplayPage(allLabelAndTextField,allPanel,card);
            }
        });

        payPay.addActionListener(e -> {
            backToPay.setEnabled(true);
            backToPay.changeColor("green");
            int n = JOptionPane.showConfirmDialog(userFrame, "Confirm to pay？",
                    "",JOptionPane.YES_NO_OPTION);
            if (n==0){
                if (dataOperator.withDraw(allLabelAndTextField.getCost())){
                    backToSeatChoose.setEnabled(false);
                    backToSeatChoose.changeColor("grey");
                    backToMealChoose.setEnabled(false);
                    backToMealChoose.changeColor("grey");
                    backToDisplay.setEnabled(false);
                    backToDisplay.changeColor("grey");
                    allPanel.payProcess(this,allLabelAndTextField,card);
                    ifPayed = true;
                    payFinish.changeColor("green");
                }else {
                    JOptionPane.showMessageDialog(userFrame, "Sorry, but your credit card is overdrawn. Please cancel additional meals or upgrade service.","Pay for failure",JOptionPane.ERROR_MESSAGE);
                    toDisplayPage(allLabelAndTextField,allPanel,card);
                }

            }
        });
        payCancel.addActionListener(e -> toDisplayPage(allLabelAndTextField,allPanel,card));
        payFinish.addActionListener(e -> {
            backToSeatChoose.setEnabled(true);
            backToSeatChoose.changeColor("green");
            backToMealChoose.setEnabled(true);
            backToMealChoose.changeColor("green");
            backToDisplay.setEnabled(true);
            backToDisplay.changeColor("green");
            backToPay.setEnabled(false);
            backToPay.changeColor("grey");
            backToPrinting.setEnabled(true);
            backToPrinting.changeColor("green");
            displaySeatChoose.setEnabled(false);
            displaySeatChoose.changeColor("grey");
            displayMealChoose.setEnabled(false);
            displayMealChoose.changeColor("grey");
            card.show(allPanel.getCenterPanel(),"Printing page");
        });

        printAll.addActionListener(e -> {
            backToSeatChoose.setEnabled(false);
            backToSeatChoose.changeColor("grey");
            backToMealChoose.setEnabled(false);
            backToMealChoose.changeColor("grey");
            backToDisplay.setEnabled(false);
            backToDisplay.changeColor("grey");
            allPanel.printProcess(this,allLabelAndTextField,card);
            printFinish.changeColor("green");
        });
        printingBack.addActionListener(e -> toDisplayPage(allLabelAndTextField,allPanel,card));
        printFinish.addActionListener(e -> {
            dataOperator.chooseSeat(targetSeat);
            for (int i = 0; i < allPanel.getMealsChooseNum().length; i++) {
                if (allPanel.getMealsChooseNum()[i] ==1)
                    dataOperator.chooseMeal(allPanel.getMealsName()[i],1);
            }
            for (int i = 0; i < allPanel.getExtraMealsChooseNum().length; i++) {
                if (allPanel.getExtraMealsChooseNum()[i] != 0)
                    dataOperator.chooseMeal(allPanel.getExtraMealsName()[i],allPanel.getExtraMealsChooseNum()[i]);
            }
            userFrame.init();
        });

    }

    /**
     * When go to the pay page, this method will be called.
     * Get all the information about the paying and display it in pay page, and show the pay page.
     * @param dimension All the dimension information.
     * @param allLabelAndTextField All the JLabel and JTextField objects.
     * @param allPanel All the JPanel objects.
     * @param card The CardLayout object of the center panel.
     * @param getData The object to get data according to the login account.
     */
    private void toPayPage(SetDimension dimension,AllLabelAndTextField allLabelAndTextField,AllPanel allPanel,CardLayout card,GetData getData){
        allLabelAndTextField.createPayTable(dimension,allPanel,getData,targetSeat);
        allPanel.createPayPage(dimension,allLabelAndTextField,this);
        backToPay.setEnabled(true);
        backToPay.changeColor("green");
        card.show(allPanel.getCenterPanel(),"Paying page");
    }

    /**
     * When go to the display page, this method will be called.
     * @param allLabelAndTextField All the JLabel and JTextField objects.
     * @param allPanel All the JPanel objects.
     * @param card The CardLayout object of the center panel.
     */
    private void toDisplayPage(AllLabelAndTextField allLabelAndTextField,AllPanel allPanel,CardLayout card){
        StringBuilder mealsChooseText = new StringBuilder();
        for (int i = 0; i < allPanel.getMealsChooseBoxes().length; i++) {
            if (allPanel.getMealsChooseBoxes()[i].isSelected())
                allPanel.getMealsChooseNum()[i]=1;
        }
        for (int i = 0;i < allPanel.getMealsChooseNum().length;i++) {
            if(allPanel.getMealsChooseNum()[i] != 0){
                mealsChooseText.append("Normal meal: ").append(allPanel.getMealsName()[i]);
            }
        }
        extraMeal = 0;
        for (int i = 0; i < allPanel.getExtraMealsChooseNumBoxes().length; i++) {
            allPanel.getExtraMealsChooseNum()[i] = allPanel.getExtraMealsChooseNumBoxes()[i].getSelectedIndex();
        }
        for (int i = 0;i < allPanel.getExtraMealsChooseNum().length;i++) {
            if(allPanel.getExtraMealsChooseNum()[i] != 0){
                extraMeal++;
            }
        }
        if (extraMeal != 0){
            mealsChooseText.append("  &&  Extra meals: ");
            for (int i = 0;i < allPanel.getExtraMealsChooseNum().length;i++) {
                if(allPanel.getExtraMealsChooseNum()[i] != 0){
                    mealsChooseText.append(allPanel.getExtraMealsName()[i].toString());
                    mealsChooseText.append("x");
                    mealsChooseText.append(allPanel.getExtraMealsChooseNum()[i]);
                    mealsChooseText.append("  ");
                }
            }
        }

        allLabelAndTextField.getFood().setText(mealsChooseText.toString());
        card.show(allPanel.getCenterPanel(), "Display page");
    }

    /**
     * The method is used to set the dimension for all the button.
     * @param dimension All the dimension information.
     */
    private void setButtonSize(SetDimension dimension){

        exitButton.setPreferredSize(dimension.getNav_Exit());
        backToOrigin.setPreferredSize(dimension.getNav());
        backToDisplay.setPreferredSize(dimension.getNav());
        backToSeatChoose.setPreferredSize(dimension.getNav());
        backToMealChoose.setPreferredSize(dimension.getNav());
        backToPay.setPreferredSize(dimension.getNav());
        backToPrinting.setPreferredSize(dimension.getNav());
        lastButton.setPreferredSize(dimension.getNav());
        nextButton.setPreferredSize(dimension.getNav());

        originBooking.setPreferredSize(dimension.getSide_button());
        originID.setPreferredSize(dimension.getSide_button());
        originScan.setPreferredSize(dimension.getSide_button());

        originConfirm.setPreferredSize(dimension.getSide_button());

        buttonInSeatChooseConfirm.setPreferredSize(dimension.getSide_button());
        buttonInSeatChooseCancelSelect.setPreferredSize(dimension.getSide_button());

        buttonInMealChooseConfirm.setPreferredSize(dimension.getSide_button());
        buttonInMealChooseCancelSelect.setPreferredSize(dimension.getSide_button());
        buttonInMealChooseReturn.setPreferredSize(dimension.getSide_button());

        buttonInExtraSeatChooseConfirm.setPreferredSize(dimension.getSide_button());
        buttonInExtraSeatChooseCancelSelect.setPreferredSize(dimension.getSide_button());
        buttonInExtraSeatChooseReturn.setPreferredSize(dimension.getSide_button());

        buttonInExtraMealChooseConfirm.setPreferredSize(dimension.getSide_button());
        buttonInExtraMealChooseCancelSelect.setPreferredSize(dimension.getSide_button());
        buttonInExtraMealChooseReturn.setPreferredSize(dimension.getSide_button());

        displayMealChoose.setPreferredSize(dimension.getSide_button());
        displaySeatChoose.setPreferredSize(dimension.getSide_button());
        checkIn.setPreferredSize(dimension.getSide_button());

        payFinish.setPreferredSize(dimension.getSide_button());
        payPay.setPreferredSize(dimension.getSide_button());
        payCancel.setPreferredSize(dimension.getSide_button());
        printingBack.setPreferredSize(dimension.getSide_button());
        printAll.setPreferredSize(dimension.getSide_button());
        printFinish.setPreferredSize(dimension.getSide_button());

    }
}
